<?php
if ($msg != "default") echo $msg_output; 

if ($action == "view") {
$query_authors = "SELECT * FROM users WHERE userLevel='3' ORDER BY lastName ASC"; 
$authors = mysql_query($query_authors, $connection) or die(mysql_error());
$row_authors = mysql_fetch_assoc($authors);
}

if ($action == "edit") {
$query_edit = "SELECT * FROM users WHERE id='$id'";
$edit = mysql_query($query_edit, $connection) or die(mysql_error());
$row_edit = mysql_fetch_assoc($edit);
}

?>
<?php if ($action == "view") { ?>
<p>
<span class="icon"><img src="images/arrow_left.png" border="0" align="absmiddle" /></span><a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">Back to Previous</a>
</p>
<p>
<span class="icon"><img src="images/user_add.png" border="0" align="absmiddle" /></span><a href="index.php?section=ce&action=add">Add a Content Expert?</a></p>
<table class="dataTable">
<tr>
	<th>Name</th>
    <th width="13%">User Name</th>
    <th width="18%">Email</th>
    <th width="13%">Phone</th>
    <th width="26%">Course(s) in Process</th>
    <th width="13%">Actions</th>
</tr>
<?php 
do { 
$query_courses = sprintf("SELECT * FROM courses WHERE aid='%s' AND course_complete='N'", $row_authors['id']); 
$courses = mysql_query($query_courses, $connection) or die(mysql_error());
$row_courses = mysql_fetch_assoc($courses);
$totalRows_courses = mysql_num_rows($courses);
?>
<tr style="background-color: <?php echo $color; ?>">
	<td><?php echo $row_authors['firstName']." ".$row_authors['lastName']; ?></td>
    <td class="data"><?php echo $row_authors['user_name']; ?></td>
    <td class="data"><?php echo $row_authors['email']; ?></td>
    <td class="data"><?php echo $row_authors['phone']; ?></td>
    <td class="data"><?php do { if ($row_courses['did'] == $row_user['id']) { echo "<a href='index.php?section=view_proposal&cid=".$row_courses['id']."'>"; } echo $row_courses['jiu_course_id']; if ($row_courses['did'] == $row_user['id']) { echo "</a>"; } if ($totalRows_courses > 0) echo "&nbsp;&nbsp;"; } while ($row_courses = mysql_fetch_assoc($courses)); ?></td>
    <td class="data">
    <span class="icon"><img src="images/pencil.png" border="0" align="absmiddle" /></span><a href="index.php?section=ce&action=edit&id=<?php echo $row_authors['id']; ?>">Edit CE Info</a>
    <br /><span class="icon"><img src="images/key.png" border="0" align="absmiddle" /></span><a href="index.php?section=ce&action=edit&go=password&id=<?php echo $row_authors['id']; ?>">Edit Password</a>
	<?php if ($row_user['userLevel'] == "1") { ?>
    <br /><span class="icon"><img src="images/bin_closed.png" border="0" align="absmiddle" /></span><a href="javascript:confirmation('includes/process.inc.php?dbTable=users&action=delete','id','<?php echo $row_authors['id']; ?>','Are you sure you want to delete this CE?');">Delete CE</a>
	<?php } ?>
    </td>
</tr>
<?php if ($color == $color1) { $color = $color2; } else { $color = $color1; } ?>
<?php } while ($row_authors = mysql_fetch_assoc($authors)); ?>
</table>
<?php } 
if (($action == "add") || ($action == "edit") && ($go == "default")) { ?>
<p><span class="icon"><img src="images/arrow_left.png" border="0" align="absmiddle" /></span><a href="<?php echo $_SERVER['HTTP_REFERER']; ?>">Back to Previous</a></p>
<p><span class="icon"><img src="images/arrow_left.png" border="0" align="absmiddle" /></span><a href="index.php?section=ce&action=view">Back to Content Experts List</a></p>
<table class="dataTable">
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">First Name:</td>
    <td class="data"><input name="firstName" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['firstName']; ?>" /></td>
</tr>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Last Name:</td>
    <td class="data"><input name="lastName" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['lastName']; ?>" /></td>
</tr>
<?php if ($row_user['userLevel'] <= "2") { ?>
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">User Name (No Spaces):</td>
    <td class="data"><input name="user_name" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['user_name']; ?>" /></td>
</tr>
<?php } ?>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Phone:</td>
    <td class="data"><input name="phone" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['phone']; ?>" /></td>
</tr>
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">Email Address:</td>
    <td class="data"><input name="email" type="text" size="30" value="<?php if ($action == "edit") echo $row_edit['email']; ?>" /></td>
</tr>
<input name="userLevel" type="hidden" value="3" />
<?php  if (($row_user['userLevel'] <= "2") && ($action == "add")) { ?>
<tr style="background-color: <?php echo $color2; ?>">
	<td class="dataLabel">Password:</td>
    <td class="data"><input name="password" type="text" size="30" value="" /></td>
</tr>
<?php } ?>
</table>
<?php } 
if (($action == "edit") && ($go == "password") && ($row_user['userLevel'] <= "2")) { ?>
<div class="error_msg">Use caution when changing passwords. Be sure to let the CE know their new password immediately!</div>
<p><span class="icon"><img src="images/arrow_left.png" border="0" align="absmiddle" /></span><a href="index.php?section=ce&action=view">Back to Content Experts List</a></p>
<table class="dataTable">
<tr style="background-color: <?php echo $color1; ?>">
	<td class="dataLabel">New Password:</td>
    <td class="data"><input name="password" type="text" size="30" value="" /></td>
</tr>
</table>
<?php } ?>
<?php if (($action == "add") || ($action == "edit")) { ?>
<p style="margin-top: 1.25em;"><input id="Submit" name="Submit" type="submit" class="button" value="<?php if ($action == "edit") echo "Update"; else echo "Submit"; ?>"></p>
<?php } ?>